package com.hmy.material.controller;

import com.hmy.material.domain.HmyMateriaFeedPurchase;
import com.hmy.material.domain.HmyMateriaFeedStore;
import com.hmy.material.service.PurchaseService;
import com.hmy.material.service.StoreService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * @author zxh
 * @version 1.0
 * @description: 物料管理进货表控制器
 * @date 2024/1/29 14:32
 */
@RestController
@RequestMapping("purchase")
public class PurchaseController extends BaseController {
    //进货
    @Resource
    private PurchaseService purchaseService;

    //存储
    @Resource
    private StoreService storeService;

    /**
     * 查询进货信息列表
     *
     * @param type      参数一：饲料类型
     * @param provider  参数二：供应商
     * @param dateStart 参数三：进货开始时间
     * @param dateEnd   参数四：进货结束时间
     * @return 返回查询列表
     */
    @RequiresPermissions("material:purchase:list")
    @GetMapping("list")
    public TableDataInfo selectPurchaseList(Integer type, String provider,
                                            String dateStart, String dateEnd) {
        startPage();
        List<HmyMateriaFeedPurchase> purchaseList = purchaseService.selectPurchaseList(type, provider, dateStart, dateEnd);
        return getDataTable(purchaseList);
    }

    /**
     * 新增物料进货信息
     *
     * @param purchase 进货信息对象
     * @return
     */
    @RequiresPermissions("material:purchase:add")
    @PostMapping("add")
    @Log(title = "物料管理", businessType = BusinessType.INSERT)
    public AjaxResult addPurchase(@RequestBody HmyMateriaFeedPurchase purchase) {
        //新增进货记录
        return toAjax(purchaseService.addPurchase(purchase));

    }

    /**
     * 根据ID获取单个进货信息
     *
     * @param id
     * @return
     */
    @RequiresPermissions("material:purchase:query")
    @GetMapping("getInfo/{id}")
    public AjaxResult selectPurchaseById(@PathVariable Long id) {
        return AjaxResult.success(purchaseService.selectPurchaseById(id));
    }

    /**
     * 根据ID修改进货信息
     *
     * @param purchase
     * @return
     */
    @PostMapping("update")
    @Log(title = "物料管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("material:purchase:update")
    public AjaxResult updatePurchase(@RequestBody HmyMateriaFeedPurchase purchase) {
        return toAjax(purchaseService.updatePurchase(purchase));

    }

    /**
     * 根据ID删除进货信息
     *
     * @param delIds
     * @return
     */
    @DeleteMapping("del/{delIds}")
    @RequiresPermissions("material:purchase:del")
    public AjaxResult delPurchaseById(@PathVariable Long[] delIds) {
        return toAjax(purchaseService.delPurchaseByIds(delIds));
    }
}
